package com.etc.controller;

import com.etc.dto.CountsStock;
import com.etc.entity.Commodity;
import com.etc.service.impl.CommodityServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@SessionAttributes(value = {"countsStocks","fla"})
@RequestMapping("con")
@Controller
public class CommodityController {
    @Resource
    CommodityServiceImpl commodityService;

    @RequestMapping("/show")
    public ModelAndView queryAllCommodity(Integer id){
        ModelAndView mv=new ModelAndView();
     List<Commodity> countsStocks = commodityService.queryAllCount(id);
     mv.addObject("countsStocks",countsStocks);


        mv.setViewName("redirect:../Brand_Manage.jsp");
        return mv;
    }
    @RequestMapping("/xiugai")
    public ModelAndView modifyState(int goodid,int groundingid,int business_id){
        System.out.println("修改");
        System.out.println("id"+goodid+"sid"+groundingid);
        int id=0;
        if (groundingid==0){
            id=1;
        }else {
            id=0;
        }
        ModelAndView mv=new ModelAndView();
     int con=      commodityService.modifyState(goodid, id);

     if (con==1){
         mv.addObject("fla","修改成功");
     }else {
         mv.addObject("fla","修改失败");
     }

         mv.setViewName("redirect:show.html?id="+business_id);
        return mv;
    }


    @RequestMapping("/delete")
    public ModelAndView deleteAll(Integer goodsid,Integer businessid){
        ModelAndView mv=new ModelAndView();
        int i= commodityService.delectAllGoods(businessid,goodsid);
   if (i>1){
       mv.addObject("fla","删除成功");
   }else {
       mv.addObject("fla","删除失败");
   }
        mv.setViewName("redirect:show.html?id="+businessid);
        return mv;
    }







}
